package net.lucamasini.ricette.server;

import java.io.IOException;

import javax.servlet.*;

public class OpenSessionInViewFilter implements Filter {

	private FilterConfig config;
	
	@Override
	public void init(FilterConfig c) throws ServletException {
		config = c;
	}

	@Override
	public void destroy() {
	}
	
	@Override
	public void doFilter(ServletRequest req, ServletResponse resp,
			FilterChain chain) throws IOException, ServletException {
		
		req.setAttribute("template", EntityManagerFactoryListener.jpaTemplateInContext(config.getServletContext()));
		chain.doFilter(req, resp);
	}

}
